package org.come.control;

import java.math.BigDecimal;
import java.util.List;

import org.come.Frame.TeamArenaMainJframe;
import org.come.Frame.ZhuFrame;
import org.come.Jpanel.TeamArenaMainJpanel;
import org.come.action.FromServerAction;
import org.come.entity.TeamRole;
import org.come.until.FormsManagement;
import org.come.until.GsonUtil;

import com.google.gson.reflect.TypeToken;
import com.tool.role.RoleData;

public class TeamArenaControl implements FromServerAction{
    private String type;

    public TeamArenaControl(String type) {
        this.type = type;
    }

    @Override
    public void controlMessFromServer(String mes, String type) {
        Integer typesOfEvents = 1;
        if("laddArena".equals(type)) {
            typesOfEvents = 2;
        }

        TeamArenaMainJpanel teamArenaMainJpanel = TeamArenaMainJframe.getTeamArenaMainJframe().getTeamArenaMainJpanel();
        if(mes.startsWith("D")){//拒绝队伍中有人长时间不同意退出匹配队列
            if(mes.length()>1) {
                ZhuFrame.getZhuJpanel().addPrompt2(mes.substring(1));
            }
            teamArenaMainJpanel.hideShow();
        }else if(mes.startsWith("A")){//同意
            String listStr = mes.substring(1);
            BigDecimal bigDecimal = new BigDecimal(listStr);
            if(bigDecimal.compareTo(RoleData.getRoleData().getLoginResult().getRole_id()) == 0){
                teamArenaMainJpanel.btnShow(2,typesOfEvents );
            }
            teamArenaMainJpanel.addCount(bigDecimal);
        }else if(mes.startsWith("O")){//匹配
            FormsManagement.showForm(108);
            String listStr = mes.substring(1);
            List<TeamRole> teamRoles = GsonUtil.getGsonUtil().getgson().fromJson(listStr, new TypeToken<List<TeamRole>>(){}.getType());
            teamArenaMainJpanel.showMine(teamRoles,1);
            teamArenaMainJpanel.btnShow(0,typesOfEvents);
        }else if(mes.startsWith("E")){//敌方
            String listStr = mes.substring(1);
            List<TeamRole> teamRoles = GsonUtil.getGsonUtil().getgson().fromJson(listStr, new TypeToken<List<TeamRole>>(){}.getType());
            teamArenaMainJpanel.showMine(teamRoles,0);
        }
    }

}
